{% extends 'system_template/public/base_main.html' %}
{% block cite %}
    等级管理
{% endblock %}
{% block content %}
    <div class="layui-col-md12">
        <table class="layui-table layui-form">
            <colgroup>
            <col width="40%">
            <col width="40%">
            <col width="20%">
            <col>
          </colgroup>
            <thead><tr><th>等级名称</th><th>等级积分</th><th>等级操作</th></tr></thead>
            <tbody>
                <tr>
                    <td>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="text" name="grade_name" required placeholder="请输入等级名称" class="layui-input">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="text" name="grade_integral" required placeholder="请输入等级积分（类型为整数）" class="layui-input" oninput="this.value=this.value.replace(/[^0-9]/g,'')">
                            </div>
                        </div></td>
                    <td class="td-manage">
                        <a class="but_sm" title="修改" onclick="update_grade(this,false,'添加','ADDITION')" href="javascript:;">添加</a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="layui-col-md12">
        <table class="layui-table layui-form">
        <colgroup>
            <col width="40%">
            <col width="40%">
            <col width="20%">
            <col>
          </colgroup>
            <thead>
            <tr>
                <th>等级名称</th>
                <th>等级积分</th>
                <th>等级操作</th>
            </tr>
            </thead>
            <tbody>
            {% for data in data_list %}
                <tr>
                    <td>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="text" name="grade_name" required placeholder="请输入等级名称" class="layui-input" value="{{ data.grade_name }}">
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="text" name="grade_integral" required placeholder="请输入等级积分（类型为整数）" class="layui-input" value="{{ data.grade_integral or 0 }}" oninput="this.value=this.value.replace(/[^0-9\.]/g,'')">
                            </div>
                        </div></td>
                    <td class="td-manage">
                        <a class="but_sm" title="修改" onclick="update_grade(this,{{ data.id }},'修改','UPDATE')" href="javascript:;">
                            修改</a>
                        <a class="but_sm del_but" title="删除" onclick="del(this,'{{ data.id }}')" href="javascript:;">删除</a>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
{% block footer %}
<script>
function update_grade(obj, id,title,method) {
        var tr = $(obj).parents("tr");
        var grade_name = tr.find('input[name="grade_name"]').val();
        var grade_integral = tr.find('input[name="grade_integral"]').val();
    layer.confirm('确认要'+title+'吗？', function (index) {
        $.ajax({
            type: method,
            data: {"data": id,"grade_name":grade_name,"grade_integral":grade_integral},
            dataType: "json",
            success: function (data) {
                if (data.status === 0) {
                    layer.msg(title+'成功!', {icon: 1, time: 1000});
                    setTimeout(function () {
                        window.location.reload();
                    }, 2000);
                } else {
                    layer.msg(title+'失败: ' + data.msg, {icon: 2, time: 2000});
                }
            }, error: function (data) {
                layer.msg('操作异常!', {icon: 7, time: 2000});
            }
        });
    });
    return false;
}
</script>
{% endblock %}